package laMalinche.testingPlayGround.aspect;

import org.aspectj.lang.annotation.*;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.JoinPoint;
import laMalinche.DevMode;
//import  java.beans.ReflectionUtils;

/**
 * Created by IntelliJ IDEA.
 * User: ranran
 * Date: Jul 24, 2009
 * Time: 7:28:00 PM
 * To change this template use File | Settings | File Templates.
 * http://weblogs.java.net/blog/javaben/archive/2006/06/javabeans_bindi.html
 */
@Aspect

public class GetSetAspect {

     @Before("call(!@Excluded * (@Getter laMalinche.testingPlayGround.testModel..*).get*(..))")

        public void getAspsects(JoinPoint thisJoinPoint){

    if( DevMode.getInstance().getInjector() == null){

        return;

    }

       String s = thisJoinPoint.getSignature().getName();

       if (s.equals("getOgnl")){

           return;

       }

       String fieldName = s.replace("get","").toLowerCase();

    PropertyChangeSupportMap.getInstance().fireAccessReport(thisJoinPoint.getTarget(),fieldName);

}

//    @After("get(@Property * *)")
//    public void timeElapsed(JoinPoint jp) throws Throwable {
//        System.out.print("set(@Property * *)" + jp);
//
//    }

//    @Around("execution(* *.setAge*(..))")
//    public void timeElapsed2(ProceedingJoinPoint jp) throws Throwable {
////   JavaBean o = (JavaBean) jp.getTarget();
//        Object o = jp.getTarget();
//        String property = ReflectionUtils.getPropertyFromAccessor(jp.getSignature().getName());
//        Object oldValue = ReflectionUtils.invokeAccessor(o, property);
//        jp.proceed();
//        Object newValue = jp.getArgs()[0];
////                o.firePropertyChange(property, oldValue, newValue);
//    }


}